package com.zts.base.exception;

import com.sun.net.httpserver.Headers;
import org.springframework.context.MessageSource;
import org.springframework.hateoas.Links;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * Created by Zhangkh on 2017/6/1.
 */
@ResponseStatus(HttpStatus.BAD_REQUEST)
public class ServiceException extends CommonException {
    private static final String DEFAULT_CODE = CommonExceptionCode.SERVICE_ERROR;

    private Integer httpStatus = null;

    private Headers headers = new Headers();

    private Links links = new Links();

    public ServiceException() {
        super(DEFAULT_CODE);
        setCode(DEFAULT_CODE);
    }

    //传入 code 和消息，将消息保存至Exception的message中，同时设置code。
    protected ServiceException(String code, String message) {
        super(message);
        setCode(code);
    }

    public ServiceException(String message, Object... args) {
        super(message, args);
        setCode(DEFAULT_CODE);
    }

    public ServiceException(Throwable cause) {
        super(cause, DEFAULT_CODE);
        setCode(DEFAULT_CODE);
    }

    public ServiceException(Throwable cause, String message, Object... args) {
        super(cause, message, args);
        setCode(DEFAULT_CODE);
    }

    public ServiceException(MessageSource messageSource, String code, Object... args) {
        super(messageSource, code, args);
    }

    public ServiceException(Throwable cause, MessageSource messageSource, String code, Object... args) {
        super(cause, messageSource, code, args);
    }

    public Integer getHttpStatus() {
        return httpStatus;
    }

    public ServiceException setHttpStatus(int httpStatus) {
        this.httpStatus = httpStatus;
        return this;
    }

    public Headers getHeaders() {
        return headers;
    }

    public ServiceException setHeaders(Headers headers) {
        this.headers = headers;
        return this;
    }

    public Links getLinks() {
        return links;
    }

    public ServiceException setLinks(Links links) {
        this.links = links;
        return this;
    }
}